// thread.h
// Copyright (C) 2008 Sam Bateman
// samuel.bateman@gmail.com
//
// This file is part of DVD On Fire.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

//! @file thread.h
//! @author Sam Bateman
//! @brief Header file for the Thread class.

#ifndef _YBJ_DOF_THREAD_H
#define _YBJ_DOF_THREAD_H

namespace dvdonfire
{
    namespace lib
    {
        // class Runnable {{{
        //! @brief Runnable thread object.
        //!
        //! Runnable thread object.  Any class that inherits from this can be
        //! passed to Thread to call its run() function in a separate thread
        //! of execution.
        class Runnable
        {
        public:
            virtual void run() = 0;
        };
        // }}}
        // class Thread {{{
        //! @brief Multithreading support.
        //!
        //! Separate thread of execution.  Thsi provides a convenient
        //! interface for running a function (a "Runnable") in a new thread.
        //! The thread doesn't actually begin until the start() method is
        //! called.  For good performance, the yield() function should be
        //! called every once in a while from inside the thread.
        class Thread
        {
        public:
            // constructor and destructor
            Thread(Runnable *r);
           ~Thread();

            // functions for using threads
            void start();
            void stop();
            bool yield();

        private:
            // implementation
            struct Impl;
            Impl *impl;
        };
        // }}}
    }
}

#endif  // _YBJ_DOF_THREAD_H
